package com.jl.commons.quartz.job;

import com.jl.commons.constant.Constants;
import com.jl.commons.utils.CopyBean;
import com.jl.model.CycleTask;
import com.jl.model.InspectionTask;
import com.jl.service.IInspectionTaskService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Date;

/**
 * 新增加巡检维护指令的 定时任务
 * @author JiangJian
 */
public class AddInspectionTaskJob extends QuartzJobBean {

    private static Logger log = LoggerFactory.getLogger(CheckComponentLifeJob.class);

    @Autowired
    private IInspectionTaskService iInspectionTaskService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("开始新增加巡检维护指令；执行时间: " + new Date());
        //TODO
        CycleTask cycleTask = (CycleTask) jobExecutionContext.getJobDetail().getJobDataMap().get(Constants.CYCLE_TASK);
        InspectionTask inspectionTask = CopyBean.cycleTaskToInspectionTask(cycleTask);
        log.info("*************执行插入任务功能**************");
        iInspectionTaskService.save(inspectionTask);

    }
}
